package com.qyer.search.DeserializerProcessor;

import com.qyer.log.WarningLogger;
import com.qyer.search.filter.AbstractFilter;
import com.qyer.search.model.SearchParameterEntity;
import com.qyer.search.model.aggregation.AggregationProduct;
import com.qyer.search.model.aggregation.AggregationRegular;
import com.qyer.search.model.result.SearchEntity;
import com.qyer.search.utils.ModelUtils;

import java.util.*;
import java.util.concurrent.Callable;

/**
 * Created by tangzheng on 16/8/3.
 */
public class VSKUDesAllProcessor implements Callable<SearchEntity> {

  private SearchParameterEntity sp;
  private List<String> resultStringList;
  private int result_mode;
  private List<AbstractFilter> filters;
  private Set<Integer> setSTG;
  private AggregationRegular regular;
  private long submitTime = 0;

  public VSKUDesAllProcessor(SearchParameterEntity sp, List<String> resultStringList,
                                      int result_mode, List<AbstractFilter> filters,
                                      Set<Integer> productCensus, AggregationRegular regular,
                                      long submitTime) {
    this.sp = sp;
    this.resultStringList = resultStringList;
    this.result_mode = result_mode;
    this.filters = filters;
    this.setSTG = productCensus;
    this.regular = regular;
    this.submitTime = submitTime;
  }

  @Override public SearchEntity call() throws Exception {

    //System.out.println("SearchEntity Call all go~");
    long t1 = System.currentTimeMillis();
    //System.out.println(Thread.currentThread().getId() +" START TIME:" + (t1 - submitTime));
    WarningLogger.logWarning("s:" + this.submitTime + ":e:" + System.currentTimeMillis(), sp);
    int size = filters.size();
    if(size == 0){
      SearchEntity searchEntity = ModelUtils
        .packageAll(sp, resultStringList, null, regular, setSTG, result_mode);
      long t2 = System.currentTimeMillis();
      //System.out.println(Thread.currentThread().getId() +" DE TIME:" + (t2 - t1));
      return searchEntity;
    }else {
      SearchEntity searchEntity = ModelUtils.packageAll(sp, resultStringList, filters, regular, setSTG, result_mode);
      long t2 = System.currentTimeMillis();
      //System.out.println(Thread.currentThread().getId() +" DE TIME:" + (t2 - t1));
      return searchEntity;
    }
  }
}
